<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*, myclasses.*, support.*, java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Verification</title>
</head>
<h1>Summary</h1>
<body>
<%
	String spes = request.getParameter("specialization");
	Student stud = (Student)session.getAttribute("student");
	stud.setSpecialization(spes);
	
	/*print info*/
	try {
		Class.forName("org.postgresql.Driver");
	} catch(Exception e) {
		out.println("org.postgresql.Driver Exception.");
	}

	try {
		String serverName = "localhost:5432";
	    String mydatabase = "ThirdBase";
	    String url = "jdbc:postgresql://" + serverName + "/" + mydatabase; 
	    String username = "SweetAss";
	    String password = "1234";
	    Connection conn = DriverManager.getConnection(url, username, password);
	    
		Statement stmt = conn.createStatement();
		
		out.println("<h4>Personal information</h4>");
		out.println("First name: " + stud.getFirstName() + "</br>");
		out.println("Middle initial: " + stud.getMiddleInitial() + "</br>");
		out.println("First name: " + stud.getLastName() + "</br>");
		
		ResultSet rset = stmt.executeQuery("SELECT name FROM specialization WHERE id = " + spes);
		rset.next();
		out.println("Specialiation: " + rset.getString(1) + "</br>");
		
		rset = stmt.executeQuery("SELECT name FROM country WHERE id = " + stud.getCitizenshipId());
		rset.next();
		out.println("Country of citizenship: " + rset.getString(1) + "</br>");

		rset = stmt.executeQuery("SELECT name FROM country WHERE id = " + stud.getResidenceId());
		rset.next();
		out.println("Country of residence: " + rset.getString(1) + "</br>");
		
		out.println("<h4>Contact info</h4>");
		Address a = stud.getAddress();
		out.println(a.printAddress());
		
		LinkedHashSet<Degree> degs = stud.getDegrees();
		out.println("<h4>Degrees</h4>");
		for (Degree d : degs) {
	
	rset = stmt.executeQuery("SELECT name FROM location WHERE id = " + d.getLocation());
	rset.next();
	out.println("Location: " + rset.getString(1) + "</br>");
	rset = stmt.executeQuery("SELECT name FROM university WHERE id = " + d.getUniversity());
	rset.next();
	out.println("University: " + rset.getString(1) + "<br>");
	
	rset = stmt.executeQuery("SELECT name FROM major WHERE id = " + d.getDiscipline());
	rset.next();
	out.println("Discipline: " + rset.getString(1) + "</br>");
	
	rset = stmt.executeQuery("SELECT name FROM title WHERE id = " + d.getName());
	rset.next();
	out.println("Name: " + rset.getString(1) + "</br></br>");
		}
		
		rset.close();
		stmt.close();
    	conn.close();
    
	} catch(SQLException e) {
		e.printStackTrace();
		out.println("Connection exception.");
	}
%>
<form action="confirmation.jsp">
<input type="submit" value="Submit"/>
</form>

<form action="cancelation.html">
<input type="submit" value="Cancel"/>
</form>

</body>
</html>